package com.beauty.mapper;

import com.beauty.models.Comment;
import org.apache.ibatis.annotations.Select;

import java.util.List;

//四个注解@Select、@Delete、@Insert、@Update就不用在xml文件写sql语句
public interface ICommentMapper {
    /**
     *  插入评论
     * @param id
     * @param noteId
     * @param content
     * @param createDate
     * @param favoriteCount
     * @param parentId
     * @param userId
     */
    @Select("INSERT INTO comment VALUES (#{id},#{noteId},#{content},#{createDate},#{favoriteCount},#{parentId},#{userId})")
    void insertComment(String id, String noteId, String content, long createDate, int favoriteCount, String parentId, String userId);

    /**
     * 获得评论列表
     * @param offset
     * @param pageSize
     * @param noteId
     * @return
     */
    @Select("SELECT * FROM comment WHERE noteId = #{noteId} ORDER BY CreateDate ASC LIMIT  #{offset}, #{pageSize} ")
    List<Comment> getCommentList(int offset, int pageSize, String noteId);

    /**
     * 获得评论的数量
     * @param noteId
     * @return
     */
    @Select("SELECT COUNT(*) FROM comment WHERE noteId = #{noteId}")
    int getCommentListCount(String noteId);
}
